package com.aichan.aibi.common;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author mengyu
 * @date 2024/03/03 9:33
 * 通用返回类
 */
@Data
@AllArgsConstructor
public class BaseResponse<T> implements Serializable {

    private Integer code;

    private T data;

    private String message;

    public static <T> BaseResponse<T> success(Integer code, T data) {
        return new BaseResponse<T>(code, data, "");
    }

    public static <T> BaseResponse<T> error(Integer code, String msg) {
        return new BaseResponse<T>(code, null, msg);
    }

    public static <T> BaseResponse<T> ok(T data) {
        return new BaseResponse<>(ErrorCode.SUCCESS.getCode(), data, "");
    }

    public static <T> BaseResponse<T> allArgs(Integer code, T data, String msg) {
        return new BaseResponse<T>(code, data, msg);
    }
}
